package com.product.timeTask;


//import com.coalSystem.entity.BasicMust;
//import com.coalSystem.service.BasicMustService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @description: CodeCache
 * 全局变量
 * @date: 2021/3/26
 * @author: 王瑾
 */
@Slf4j
@Component
public class CodeCache {

    public static Map<String, Map> basicMustCode = new HashMap<>();

//    @Autowired
//    BasicMustService basicMustService;


    @PostConstruct
    public void init() {
//        List<BasicMust> basicMustList = basicMustService.list();
//        Map<String, List<BasicMust>> deviceMap = basicMustList.stream().collect(Collectors.groupingBy(map -> {
//            if ("".equals(String.valueOf(map.getType()))) {
//                return "OTHER";
//            } else {
//                return String.valueOf(map.getType());
//            }
//        }));
//        for (String key : deviceMap.keySet()) {
//            basicMustCode.put(key, deviceMap.get(key).stream().collect(Collectors.toMap(BasicMust::getCode, BasicMust::getValue)));
//        }
    }

    @PreDestroy
    public void destroy() {
        //系统运行结束
    }

    @Scheduled(cron = "0 0 0/2 * * ?")
    public void testOne() {
        //每2小时执行一次缓存
        init();
    }

}